// $ANTLR 3.0.1 C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g 2008-05-10 15:07:09

	package patternmining.model.construction;
	

	import java.util.Map;
	import java.util.HashMap;



import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

class BPSLASTSinglePass extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "DISJUNCTION", "ROOT", "VARDEF", "FORMULA", "CLASSDEF", "TYPEDVARDEF", "METHODDEF", "PATTERNNAME", "ID", "PREDICATE", "WS", "':='", "'\\exist'", "','", "'\\element'", "';'", "'\\C'", "'\\V'", "'\\M'", "'('", "')'"
    };
    public static final int TYPEDVARDEF=9;
    public static final int DISJUNCTION=4;
    public static final int WS=14;
    public static final int FORMULA=7;
    public static final int METHODDEF=10;
    public static final int PATTERNNAME=11;
    public static final int CLASSDEF=8;
    public static final int VARDEF=6;
    public static final int ID=12;
    public static final int EOF=-1;
    public static final int ROOT=5;
    public static final int PREDICATE=13;

        public BPSLASTSinglePass(TreeNodeStream input) {
            super(input);
        }
        

    public String[] getTokenNames() { return tokenNames; }
    public String getGrammarFileName() { return "C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g"; }



    // $ANTLR start specification
    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:42:1: specification returns [ModelData modelData] : a= PATTERNNAME ( ^( CLASSDEF (a= ID )+ ) | ^( TYPEDVARDEF (a= ID )+ ) | ^( METHODDEF (a= ID )+ ) )+ ( ^(c= PREDICATE a= ID b= ID ) )* ;
    public final ModelData specification() throws RecognitionException {
        ModelData modelData = null;

        CommonTree a=null;
        CommonTree c=null;
        CommonTree b=null;

        
        				Map<String, BPSLTermType> symbols = new HashMap<String, BPSLTermType>();
        				BPSLPredicateSpace predicates = BPSLPredicateSpace.getInstance();
        				modelData = new ModelData();
        				String nameSpace;
        			 
        try {
            // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:49:4: (a= PATTERNNAME ( ^( CLASSDEF (a= ID )+ ) | ^( TYPEDVARDEF (a= ID )+ ) | ^( METHODDEF (a= ID )+ ) )+ ( ^(c= PREDICATE a= ID b= ID ) )* )
            // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:49:6: a= PATTERNNAME ( ^( CLASSDEF (a= ID )+ ) | ^( TYPEDVARDEF (a= ID )+ ) | ^( METHODDEF (a= ID )+ ) )+ ( ^(c= PREDICATE a= ID b= ID ) )*
            {
            a=(CommonTree)input.LT(1);
            match(input,PATTERNNAME,FOLLOW_PATTERNNAME_in_specification59); 
             nameSpace = a.getText(); nameSpace = nameSpace.trim(); nameSpace = nameSpace.substring(1); 
            // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:50:5: ( ^( CLASSDEF (a= ID )+ ) | ^( TYPEDVARDEF (a= ID )+ ) | ^( METHODDEF (a= ID )+ ) )+
            int cnt4=0;
            loop4:
            do {
                int alt4=4;
                switch ( input.LA(1) ) {
                case CLASSDEF:
                    {
                    alt4=1;
                    }
                    break;
                case TYPEDVARDEF:
                    {
                    alt4=2;
                    }
                    break;
                case METHODDEF:
                    {
                    alt4=3;
                    }
                    break;

                }

                switch (alt4) {
            	case 1 :
            	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:51:5: ^( CLASSDEF (a= ID )+ )
            	    {
            	    match(input,CLASSDEF,FOLLOW_CLASSDEF_in_specification74); 

            	    match(input, Token.DOWN, null); 
            	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:51:16: (a= ID )+
            	    int cnt1=0;
            	    loop1:
            	    do {
            	        int alt1=2;
            	        int LA1_0 = input.LA(1);

            	        if ( (LA1_0==ID) ) {
            	            alt1=1;
            	        }


            	        switch (alt1) {
            	    	case 1 :
            	    	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:51:17: a= ID
            	    	    {
            	    	    a=(CommonTree)input.LT(1);
            	    	    match(input,ID,FOLLOW_ID_in_specification79); 
            	    	    	
            	    	    					if ( ! symbols.containsKey(a.getText()) ) {
            	    	    						//add variable to the symbol table
            	    	    						symbols.put(a.getText(), BPSLTermType.CLASS);
            	    	    						//add term as vertex to the graph under construction
            	    	    						modelData.addTermData( new TermData( nameSpace + "." + a.getText(), a.getLine(), a.getCharPositionInLine(), BPSLTermType.CLASS ) );
            	    	    					}
            	    	    					else {
            	    	    						// variable already used. treat errror
            	    	    					}
            	    	    				

            	    	    }
            	    	    break;

            	    	default :
            	    	    if ( cnt1 >= 1 ) break loop1;
            	                EarlyExitException eee =
            	                    new EarlyExitException(1, input);
            	                throw eee;
            	        }
            	        cnt1++;
            	    } while (true);


            	    match(input, Token.UP, null); 

            	    }
            	    break;
            	case 2 :
            	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:66:5: ^( TYPEDVARDEF (a= ID )+ )
            	    {
            	    match(input,TYPEDVARDEF,FOLLOW_TYPEDVARDEF_in_specification107); 

            	    match(input, Token.DOWN, null); 
            	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:66:19: (a= ID )+
            	    int cnt2=0;
            	    loop2:
            	    do {
            	        int alt2=2;
            	        int LA2_0 = input.LA(1);

            	        if ( (LA2_0==ID) ) {
            	            alt2=1;
            	        }


            	        switch (alt2) {
            	    	case 1 :
            	    	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:66:20: a= ID
            	    	    {
            	    	    a=(CommonTree)input.LT(1);
            	    	    match(input,ID,FOLLOW_ID_in_specification112); 
            	    	    
            	    	    					if ( ! symbols.containsKey(a.getText()) ) {
            	    	    						//add variable to the symbol table
            	    	    						symbols.put(a.getText(), BPSLTermType.TYPEDVARIABLE);
            	    	    						//add term as vertex to the graph under construction
            	    	    						modelData.addTermData( new TermData( nameSpace + "." + a.getText(), a.getLine(), a.getCharPositionInLine(), BPSLTermType.TYPEDVARIABLE ) );
            	    	    					}
            	    	    					else {
            	    	    						// variable allready used. treat errror
            	    	    					}	
            	    	    				

            	    	    }
            	    	    break;

            	    	default :
            	    	    if ( cnt2 >= 1 ) break loop2;
            	                EarlyExitException eee =
            	                    new EarlyExitException(2, input);
            	                throw eee;
            	        }
            	        cnt2++;
            	    } while (true);


            	    match(input, Token.UP, null); 

            	    }
            	    break;
            	case 3 :
            	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:82:5: ^( METHODDEF (a= ID )+ )
            	    {
            	    match(input,METHODDEF,FOLLOW_METHODDEF_in_specification145); 

            	    match(input, Token.DOWN, null); 
            	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:82:17: (a= ID )+
            	    int cnt3=0;
            	    loop3:
            	    do {
            	        int alt3=2;
            	        int LA3_0 = input.LA(1);

            	        if ( (LA3_0==ID) ) {
            	            alt3=1;
            	        }


            	        switch (alt3) {
            	    	case 1 :
            	    	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:82:18: a= ID
            	    	    {
            	    	    a=(CommonTree)input.LT(1);
            	    	    match(input,ID,FOLLOW_ID_in_specification150); 
            	    	    
            	    	    					if ( ! symbols.containsKey(a.getText()) ) {
            	    	    						//add variable to the symbol table
            	    	    						symbols.put(a.getText(), BPSLTermType.METHOD);
            	    	    						//add term as vertex to the graph under construction
            	    	    						modelData.addTermData( new TermData( nameSpace + "." + a.getText(), a.getLine(), a.getCharPositionInLine(), BPSLTermType.METHOD) );
            	    	    					}
            	    	    					else {
            	    	    						// variable allready used. treat errror
            	    	    					}	
            	    	    				

            	    	    }
            	    	    break;

            	    	default :
            	    	    if ( cnt3 >= 1 ) break loop3;
            	                EarlyExitException eee =
            	                    new EarlyExitException(3, input);
            	                throw eee;
            	        }
            	        cnt3++;
            	    } while (true);


            	    match(input, Token.UP, null); 

            	    }
            	    break;

            	default :
            	    if ( cnt4 >= 1 ) break loop4;
                        EarlyExitException eee =
                            new EarlyExitException(4, input);
                        throw eee;
                }
                cnt4++;
            } while (true);

            // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:97:5: ( ^(c= PREDICATE a= ID b= ID ) )*
            loop5:
            do {
                int alt5=2;
                int LA5_0 = input.LA(1);

                if ( (LA5_0==PREDICATE) ) {
                    alt5=1;
                }


                switch (alt5) {
            	case 1 :
            	    // C:\\Documents and Settings\\Holger.TABLET\\My Documents\\Faculdade_ano_3\\Iniciacao_Cientifica\\artefatos_produzidos\\ANTLRGrammars\\Projeto\\BPSL\\BPSL_Procesor_JUNG\\BPSLWalker.g:97:7: ^(c= PREDICATE a= ID b= ID )
            	    {
            	    c=(CommonTree)input.LT(1);
            	    match(input,PREDICATE,FOLLOW_PREDICATE_in_specification186); 

            	    match(input, Token.DOWN, null); 
            	    a=(CommonTree)input.LT(1);
            	    match(input,ID,FOLLOW_ID_in_specification190); 
            	    b=(CommonTree)input.LT(1);
            	    match(input,ID,FOLLOW_ID_in_specification194); 

            	    match(input, Token.UP, null); 
            	     
            	    					BPSLTermType aType, bType;
            	    					//verify if ID a has been declared and get his type
            	    					aType = symbols.get(a.getText());
            	    					//verify if ID b has been declard and get his type
            	    					bType = symbols.get(b.getText());
            	    					//if both have been declared verify if predicate is defined for this domain
            	    					if (aType != null && bType != null) {
            	    						//if predicate is defined add adge to graph
            	    						if ( predicates.isDefinedOnDomain(c.getText(), symbols.get(a.getText()), symbols.get(b.getText())) ){
            	    							//add atom as edge to the graph under construction
            	    							modelData.addAtomData( new AtomData( c.getLine(), c.getCharPositionInLine(), BPSLPredicateType.getEnum( c.getText() ), nameSpace + "." + a.getText(), nameSpace + "." + b.getText() ) );   	
            	    						}
            	    						//else treat error
            	    						else {
            	    						} 
            	    					
            	    					}
            	    					//else treat error
            	    					else {
            	    					}
            	    						
            	    				

            	    }
            	    break;

            	default :
            	    break loop5;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return modelData;
    }
    // $ANTLR end specification


 

    public static final BitSet FOLLOW_PATTERNNAME_in_specification59 = new BitSet(new long[]{0x0000000000000700L});
    public static final BitSet FOLLOW_CLASSDEF_in_specification74 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_specification79 = new BitSet(new long[]{0x0000000000001008L});
    public static final BitSet FOLLOW_TYPEDVARDEF_in_specification107 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_specification112 = new BitSet(new long[]{0x0000000000001008L});
    public static final BitSet FOLLOW_METHODDEF_in_specification145 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_specification150 = new BitSet(new long[]{0x0000000000001008L});
    public static final BitSet FOLLOW_PREDICATE_in_specification186 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_specification190 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_ID_in_specification194 = new BitSet(new long[]{0x0000000000000008L});

}